<script setup>
// let treeData = [
//   {
//     title:"张三",
//     key: "1",
//     children: [
//       {
//         title:"张三三",
//         key:"1-1",
//         外号:"张三丰"
//       },
//       {
//         title:"张三四",
//         key:"1-2"
//       }
//     ]
//   },
//   {
//     title:"李四",
//     key: "2",
//   }
// ]
import axios from "axios";
import globalParams from "@/GlobalParams.js";

let treeData = []

let node1 = {}
node1.key="1";
node1.title="张三";
node1["aaa.aa"] = "asdfasdfasdf"
node1.children=[];

let subNode1={}
subNode1.key="1-1";
subNode1.title = "张三三"
node1.children.push(subNode1)
treeData.push(node1);

let node2 = {}
node2.key="2";
node2.title="李四";
treeData.push(node2);



function selectHandle(a,b){
  console.log(a)
  console.log(b)
  console.log("您选中了节点的文字是："+b.node.title+", 值是："+b.node.key+",外号是："+b.node.外号)
}

function clickHandle(){
  let user = {}
  user.tableKey="1111112222";
  user.userName="ls"
  user.realName='李四'

  let paras = {}
  paras.userInfo = JSON.stringify(user)

  // axios.post(globalParams.postUrl+"/users/addUser", user, {headers: {'Content-Type': 'application/json'}}).then(res => {
  //   if(res.data==="success"){
  //     alert("添加成功")
  //   }
  //   else {
  //     alert("添加失败")
  //   }
  // })

  console.log(paras)
  axios.post(globalParams.postUrl+"/users/addUser2",paras).then((res) => {
    console.log(res)
  })
}
</script>

<template>
  <a-tree
      :tree-data="treeData"
      :expandedKeys="['1']"
      checkable
      @select="selectHandle"
  >
    <template #title="{ title, key }">
      <span v-if="key === '1-1'" style="color: #f00">{{ title }}</span>
      <template v-else>{{ title }}</template>
    </template>
  </a-tree>

  <input type="button" value="插入一个用户" @click="clickHandle" />
</template>

<style scoped>

</style>